<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>发送web消息</title>
</head>
<body>
<script>
    let ws = new WebSocket("ws://192.168.56.10:9501");
    ws.onopen = function () {
        console.log('建立连接了');
    }
    //接收服务器传递过来的消息
    //{data} 是 es6 的结构赋值
    ws.onmessage = function ({data}) {
        console.log(data);
    }

    ws.onclose = ()=>{
        console.log('服务已经结束');
    }

    setInterval(()=>{
        ws.send('456');
    },2000);
</script>
</body>
</html>